<?php
error_reporting(0);
header("Content-type:text/html;charset=utf-8");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: *");
header("Access-Control-Allow-Headers: *");//这里“Access-Token”是我要传到后台的内容key
header("Access-Control-Expose-Headers: *");
require_once "cache.php";
if($_SERVER['REQUEST_METHOD']=='OPTIONS'){
    echo return_data(false,"不支持OPTIONS请求","");
    return;
}
$fileIo = file_get_contents('php://input');
$param = json_decode($fileIo,true);
if($_GET['type'] == "0"){
    // 获取配置
    $config = cacheGet("config","config");
    if(!$config){
        echo return_data(false,"当前系统未被配置过",null);
        return;
    }
    $config['password'] = "";
    echo return_data(true,"读取成功",$config);
}else if($_GET['type'] == "1"){
    // 设置配置
    if(!$param['password']){
        echo return_data(false,"请输入密码","");
        return;
    }
    $config = cacheGet("config","config");
    if($config){
        if($param['password'] != $config['password']){
            echo return_data(false,"密码错误",null);
            return;
        }
    }
    cacheSet("config","config",$param);
    echo return_data(true,"设置成功",null);
}else{
    echo return_data(false,"此方法暂不支持","");
}


